﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.AccessControl;
using System.Text;

namespace SimplyConfigured.Tests
{
    internal class Common
    {
        public static void CreateAppConfig()
        {
            var content = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<configuration>
  <connectionStrings>
    <add name=""SimplyConfigured"" connectionString=""Server=.;Database=SimplyConfigured;Trusted_Connection=True;""/>
  </connectionStrings>
  <configSections>
  </configSections>
  <appSettings>
    <add key=""testKey"" value=""testValue"" />
    <add key=""testList"" value=""One, Two, Three, Four"" />
    <add key=""Trim Whitespaces"" value=""one, two  , thre,four,   five,""/>
    <add key=""testInteger"" value=""123""/>
    <add key=""testDecimal"" value=""123.4567890123""/>
    <add key=""testDouble"" value=""123.45678""/>
  </appSettings>
</configuration>";

            using(var file = File.Create("App.config"))
            {
                var info = new UTF8Encoding().GetBytes(content);
                file.Write(info, 0, info.Length);
            }

        }

        public static string GetBaseDirectory()
        {
            var dir = Environment.CurrentDirectory;
            return dir;
        }

        public static void DeleteAppConfig()
        {
            File.Delete("App.config");
        }

        internal static void DeleteAppIni()
        {
            File.Delete("App.ini");
        }

        internal static void CreateAppIni()
        {
            var content = @"; last modified 1 April 2011 by John Doe
; this is a sample ini file to test the ini parser.

; no-category values:
dupvalue=from:IniConfigurationSource

[Owner]
name=John Doe
organization=Polaris Industries Inc
 
[database]
server=192.0.2.62						; use IP address in case network name resolution is not working
port=154								; arbitrary port
file = ""payroll.dat""					; this value appears in quotes and has a space after the equal sign.";


            using (var file = File.Create("App.ini"))
            {
                var info = new UTF8Encoding().GetBytes(content);
                file.Write(info, 0, info.Length);
            }

        }
    }
}
